package logic.trails;

import java.util.ArrayList;
import java.util.List;

import logic.weapons.WeaponFire;
import logic.weapons.WeaponFireVisibility;
import logic.weapons.projectileWeapons.Projectile;

import com.jme.math.Vector3f;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Cylinder;
import com.jmex.effects.TrailMesh;

import factories.EffectFactory;

public class WeaponFireTrail extends AbstractTrail {
	
	private static final long serialVersionUID = 1L;
	
	public static final int HIGH_QUAL_STEPS = 2;
	public static final int MED_QUAL_STEPS = 3;
	public static final int LOW_QUAL_STEPS = 4;
	
	public static final float DELAY_INC = 10f;
	
	private WeaponFire fire;
	
	private boolean onlyVisibleOnce;
	
	public WeaponFireTrail(float width, WeaponFire fire) {
		super(fire, width, fire.getIngameState(), HIGH_QUAL_STEPS, MED_QUAL_STEPS, LOW_QUAL_STEPS, DELAY_INC);
		this.fire = fire;
		
		onlyVisibleOnce = WeaponFireVisibility.movesAwayFrom(fire, fire.getIngameState().getCam().getLocation());
		
		init();
	}
	
	@Override
	protected void setVisible(boolean vis) {
		super.setVisible(vis);
		if(!trailVis.isVisible() && onlyVisibleOnce) deleteTrail();
	}
	
	@Override
	protected List<TrailMesh> getHighTrailMeshes() {
		List<TrailMesh> trailMeshes = new ArrayList<TrailMesh>();
		
		trailMeshes.add(EffectFactory.getWeaponFireTrail(EffectFactory.blue));
		trailMeshes.add(EffectFactory.getWeaponFireTrail(EffectFactory.yellow));
		trailMeshes.add(EffectFactory.getWeaponFireTrail(EffectFactory.yellow));
		
		return trailMeshes;
	}
	
	@Override
	protected List<TrailMesh> getMediumTrailMeshes() {
		List<TrailMesh> trailMeshes = new ArrayList<TrailMesh>();
		
		trailMeshes.add(EffectFactory.getWeaponFireTrail(EffectFactory.blue));
		trailMeshes.add(EffectFactory.getWeaponFireTrail(EffectFactory.yellow));
		
		return trailMeshes;
	}
	
	@Override
	protected List<? extends Spatial> getLowTrailMeshes() {
		List<Spatial> objects = new ArrayList<Spatial>();
		
		Cylinder c = EffectFactory.getWeaponFireCylinder();
		if(fire instanceof Projectile) c.setLocalTranslation(0f, 0f, -c.getHeight());
		objects.add(c);
		
		return objects;
	}
	
	@Override
	public Vector3f getTrailFrontLoc() { return fire.getLocalTranslation(); }
}